package com.mrh.mall.portal.controller;

import com.mrh.mall.common.api.CommonResult;
import com.mrh.mall.portal.domain.MemberReadHistory;
import com.mrh.mall.portal.service.MemberReadHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 末日混
 * @Date: 2023年02月08日 21:51
 */

@RestController
@Api(tags = "MemberReadHistoryController", description = "会员商品浏览记录管理")
@RequestMapping("/member/readHistory")
public class MemberReadHistoryController {
    @Autowired
    MemberReadHistoryService memberReadHistoryService;

    @ApiOperation("创建浏览记录")
    @RequestMapping(value = "/create",method = RequestMethod.POST)
    public CommonResult delete(@RequestBody MemberReadHistory memberReadHistory){
        int count = memberReadHistoryService.create(memberReadHistory);
        if (count>0){
            return CommonResult.success(count);
        }else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("删除浏览记录")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public CommonResult delete(@RequestParam("ids") List<String> ids){
        int count = memberReadHistoryService.delete(ids);
        if (count>0){
            return CommonResult.success(count);
        }else {
            return CommonResult.failed();
        }
    }

    // TODO: 2023-02-08  用户登录功能完善后，获取当前用户浏览记录
    @ApiOperation("查询浏览记录")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public CommonResult<List<MemberReadHistory>> list(@RequestParam(value = "pageNum",defaultValue = "1",required = false) Integer pageNum,
                                                      @RequestParam(value = "pageSize",defaultValue = "5",required = false) Integer pageSize){
        return null;
    }
}
